package com.aaa.mapper;

import org.apache.ibatis.annotations.*;
import com.aaa.entity.WorkAttendance;

import java.util.List;

@Mapper
public interface WorkAttendanceMapper {
    /**
     * 插入打卡记录
     */
    @Insert("insert into work_attendance (user_id, user_name, check_type, work_type, " +
    "latitude, longitude, location, company_name, business_type, business_description, check_time) " +
    "values (#{userId}, #{userName}, #{checkType}, #{workType}, " +
    "#{latitude}, #{longitude}, #{location}, #{companyName}, #{businessType}, " +
    "#{businessDescription}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")//主键回填，keyProperty将生成的主键设置到实体类id上
    int insert(WorkAttendance attendance);

    /**
     * 获取用户当天的打卡记录
     */
    @Select("SELECT * FROM work_attendance WHERE user_id = #{userId} AND DATE(check_time) = CURDATE() AND status = 1 ORDER BY check_time DESC")
    List<WorkAttendance> getTodayRecords(@Param("userId") Long userId);
} 